/*
 * Copyright (c) 2010-2013 Ruben Chakhmakhchyan. All rights reserved.
 * 
 * This file contains Original Code and/or Modifications of Original Code
 * as defined in and that are subject to the Eclipse Public License
 * Version 1.0 (the 'License'). You may not use this file except in
 * compliance with the License. Please obtain a copy of the License at
 * http://opensource.org/licenses/EPL-1.0 and read it before using this file.
 */

#pragma once

#include "result_codes.h"


class AsyncInvokeArg;

typedef void ( *AsyncCallback ) ( AsyncInvokeArg* );


__interface PluginModel;


class AsyncInvokeArg
{
public:

    AsyncInvokeArg( PluginModel* model ) : m_model( model ), m_result( 0 ), m_id( 0 ), m_resultCode( ResultCode::Success ) { }

    AsyncInvokeArg( PluginModel* model, int id ) : m_model( model ), m_result( 0 ), m_id( id ), m_resultCode( ResultCode::Success ) { }

    virtual ~AsyncInvokeArg() {}

    inline PluginModel* getPluginModel() { return m_model; }

    inline ResultCode getResultCode() const { return m_resultCode; }
    inline void setResultCode( ResultCode value ) { m_resultCode = value; }

    inline int getResult() const { return m_result; }
    inline void setResult( int value ) { m_result = value; }

    inline int getId() { return m_id; }

protected:

    PluginModel* m_model;

    ResultCode m_resultCode; // async operation result code
    int m_result; // return value of the async operation
    int m_id; // user-defined identifier of the operation
};


class AsyncInvoke //abstract
{
public:

    virtual ~AsyncInvoke() {}

    virtual AsyncInvokeArg* getArg() = 0;
    virtual AsyncCallback getCallback() = 0;
};

// custom window message for async callbacks
// this define can be moved to "threading.h" if the callback is not processed in plugin/control's main window proc
#ifdef _WINDOWS
#define WM_CUSTOM_ASYNCCALLBACK		0xAF01
#endif
